/*
 * @lc app=leetcode.cn id=1716 lang=typescript
 *
 * [1716] 计算力扣银行的钱
 */

// @lc code=start
function totalMoney(n: number): number {
    let head = Math.floor(n / 7);
    let sub = n % 7;

    let final = head > 0 ? 28 * head : 0;
    let temp = head;
    while (temp) {
        final += 7 * (temp - 1);
        temp--;
    }

    while (sub) {
        final += head + sub;
        sub--;
    }
    return final;
}
// @lc code=end
